package com.caration.shell.utils;

import com.caration.shell.cr3d.SharedData;

import android.graphics.*;

public class MaskFilterUtils {
	public static final int s12density;
	public static final int s1density;
	private static final BlurMaskFilter sOuterLargeFilter;
	private static final BlurMaskFilter sOuterMidFilter;
	private static final BlurMaskFilter sOuterSmallFilter;
	private static final BlurMaskFilter sOuterSmallestFilter;
	private static final BlurMaskFilter sNormalMidFilter;
	private static final BlurMaskFilter sNormalLargeFilter;
	private static final BlurMaskFilter sNormalSmallFilter;
	private static final MaskFilter sTableMaskFilter = Reflect.createClipTable(
			0, 200);
	private final Paint c = new Paint();
	private final Paint mOutPaint = new Paint();
	private final Paint e = new Paint();
	private final Paint f = new Paint();
	private int mPoint[];

	static {
		float density = SharedData.sDensity;
		s1density = (int) (density * 1F);
		s12density = (int) (density * 12F);
		sOuterLargeFilter = new BlurMaskFilter(12F * density,
				android.graphics.BlurMaskFilter.Blur.OUTER);
		sOuterMidFilter = new BlurMaskFilter(density * 6F,
				android.graphics.BlurMaskFilter.Blur.OUTER);
		sOuterSmallFilter = new BlurMaskFilter(density * 2F,
				android.graphics.BlurMaskFilter.Blur.OUTER);
		sOuterSmallestFilter = new BlurMaskFilter(density * 1F,
				android.graphics.BlurMaskFilter.Blur.OUTER);
		sNormalLargeFilter = new BlurMaskFilter(density * 6F,
				android.graphics.BlurMaskFilter.Blur.NORMAL);
		sNormalMidFilter = new BlurMaskFilter(4F * density,
				android.graphics.BlurMaskFilter.Blur.NORMAL);
		sNormalSmallFilter = new BlurMaskFilter(density * 2F,
				android.graphics.BlurMaskFilter.Blur.NORMAL);
	}

	public MaskFilterUtils() {
		mPoint = new int[2];
		c.setFilterBitmap(true);
		c.setAntiAlias(true);
		mOutPaint.setFilterBitmap(true);
		mOutPaint.setAntiAlias(true);
		e.setXfermode(new PorterDuffXfermode(
				android.graphics.PorterDuff.Mode.DST_OUT));
		e.setFilterBitmap(true);
		e.setAntiAlias(true);
		f.setMaskFilter(Reflect.createClipTable(180, 255));
	}

	public final void drawBlurMask(Bitmap bitmap, Canvas canvas) {
		mOutPaint.setMaskFilter(sOuterMidFilter);
		Bitmap bitmap1 = bitmap.extractAlpha(mOutPaint, mPoint);
		c.setMaskFilter(sTableMaskFilter);
		c.setAlpha(150);
		c.setColor(0xff0099ff);
		canvas.drawBitmap(bitmap1, mPoint[0], mPoint[1], c);
		bitmap1.recycle();
	}
}
